package com.xrkj.b2c.controller.sys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xrkj.b2c.controller.common.BasicController;
import com.xrkj.b2c.model.sys.SysMemberAddress;
import com.xrkj.b2c.service.sys.SysMemberAddressService;
import com.xrkj.b2c.utils.StringUtil;

/**
 * 
 * <B>系统名称：</B><BR>
 * <B>模块名称：</B><BR>
 * <B>中文类名：</B>控制器<BR>
 * <B>概要说明：</B><BR>
 * 
 * 
 */
@RequestMapping("/sysMemberAddress")
@Controller
public class SysMemberAddressController extends BasicController {

    @Autowired
    protected SysMemberAddressService memberAddressService;

    private Logger logger = Logger.getLogger(SysMemberAddressController.class);

    /**
     * f
     * 
     * <B>方法名称：</B>转向管理界面<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年10月23日
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/forwardMemberAddress.do")
    public ModelAndView forwardLogin(HttpServletRequest request, HttpServletResponse response) {
        return new ModelAndView("WEB-INF/pages/sys/sys-memberAddress/memberAddress-to-manager");
    }

    /**
     * 
     * <B>方法名称：</B>用户列表<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年11月30日
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/memberAddressList")
    @ResponseBody
    public Object memberAddressList(HttpServletRequest request, HttpServletResponse response) {
        String search = request.getParameter("search");//名称
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Map<String, Object> ret = new HashMap<String, Object>();
        Map<String, Object> paramter = new HashMap<String, Object>();
        paramter.put("offset", StringUtil.isEmpty(offset) ? null : Integer.parseInt(offset));
        paramter.put("limit", StringUtil.isEmpty(limit) ? null : Integer.parseInt(limit));
        paramter.put("search", search);
        Integer total = memberAddressService.findMemberAddressTotal(paramter);
        List<SysMemberAddress> menus = new ArrayList<SysMemberAddress>();
        if (total > 0) {
            menus = memberAddressService.findMemberAddressList(paramter);
        }
        ret.put("total", total);
        ret.put("rows", menus);
        return ret;
    }

    /**
     * 
     * <B>方法名称：</B>转向新增方法<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年10月20日
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/forwardAddMemberAddress")
    public ModelAndView forwardAddMemberAddress(HttpServletRequest request, HttpServletResponse response) {
        //查询权限列表
        Map<String, Object> paramter = new HashMap<String, Object>();
        paramter.put("rStatus", 1);
        return new ModelAndView("WEB-INF/pages/sys/sys-memberAddress/add-memberAddress-dialog");
    }


    /**
     * 
     * <B>方法名称：</B>删除<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年12月1日
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/deleteMemberAddress")
    @ResponseBody
    public Map<String, Object> deleteMemberAddress(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> ret = new HashMap<String, Object>();
        String id = request.getParameter("id");
        if (memberAddressService.deleteByPrimaryKey(id) > 0) {
            //删除成功
            ret.put("success", true);
            ret.put("msg", "删除成功。");
        } else {
            //删除失败
            ret.put("success", false);
            ret.put("msg", "删除失败");
        }
        return ret;
    }

}
